<include file="public/layout" />
<script src="__ROOT__/public/static/js/layer/laydate/laydate.js"></script>
<body style="background-color: #FFF; overflow: auto;"> 
<div class="page">
  <div class="fixed-bar">
    <div class="item-title"><a class="back" href="javascript:history.back();" title="返回列表"><i class="fa fa-arrow-circle-o-left"></i></a>
      <div class="subject">
        <h3> 广告详情</h3>
        <h5>广告添加与管理</h5>
      </div>
    </div>
  </div>
    <!--表单数据-->
    <form method="post" id="handleposition" action="{:U('Admin/Ad/adHandle')}">  
    <div class="ncap-form-default">
      <dl class="row">
        <dt class="tit">
          <label><em>*</em>广告名称：</label>
        </dt>
        <dd class="opt">
          <input type="text" placeholder="名称" class="input-txt" name="ad_name" value="{$info.ad_name|default='自定义广告名称'}">
		  <span class="err" id="err_ad_name" style="color:#F00; display:none;">广告名称不能为空</span>                                                  
          <p class="notic"></p>
        </dd>
      </dl>	   
	  <dl class="row">
        <dt class="tit" colspan="2">
          <label>广告类型：</label>
        </dt>
        <dd class="opt">
          <if condition='$Request.param.is_app_ad eq 1'>
          			<select name="media_type" id="media_type" class="input-sm" class="form-control">
		                 <option value="3" <if condition="$info.media_type eq 3 ">selected</if>>商品</option>                                             
		                 <option value="4" <if condition="$info.media_type eq 4 ">selected</if>>分类</option>
		                 <option value="5" <if condition="$info.media_type eq 5 ">selected</if>>Web链接</option>
		            </select>
          <else/>
	          	 <div id="gcategory">
		            <select name="media_type" class="input-sm" class="form-control">
		                 <option value="0">图片</option>                                             
		                 <!--<option value="1">flash</option>-->
		            </select>                   
		          </div>  
          </if>	 
        </dd>
      </dl> 
      <dl class="row">
        <dt class="tit">
          <label><em>*</em>广告链接：</label>
        </dt>
        <dd class="opt" id="ad_link_dd">
        	<div id="link_url"> <!-- 网页链接 -->
        		  <input type="text" placeholder="广告链接" class="input-txt" name="ad_link" value="{$info.ad_link}">
				  <span class="err" id="err_ad_link" style="color:#F00; display:none;"></span>
		          <p class="notic"></p>
        	</div>
        	<div id="link_category"> <!-- 分类链接 -->
        		  <select name="cat_id1" id="cat_id1" onblur="get_category(this.value,'cat_id2','0');"  class="class-select valid">
	                <option value="0">请选择商品分类</option>                                      
	                     <foreach name="cat_list" item="v" key="k" >                                                                           
	                       <option value="{$v['id']}" <if condition="$v['id'] eq $info[cat_id1]">selected="selected"</if> >
	                            {$v['name']}
	                       </option>
	                     </foreach>
	              </select>
	              <select name="cat_id2" id="cat_id2" onblur="get_category(this.value,'cat_id3','0');" class="class-select valid">
	                <option value="0">请选择商品分类</option>
	              </select>    
	              <select name="cat_id3" id="cat_id3" class="class-select valid">
	                <option value="0">请选择商品分类</option>
	              </select> 
        	</div>
        	<div id="link_goods"> <!-- 商品链接 -->
        		  <a id="add_type" class="ncap-btn" onclick="select_goods_dialog()">选择商品</a> 
        		  <span id="goods_name">{$info.goods_name}</span>
        		  <input name="goods_id" id="goods_id" type="hidden" value="{$info.ad_link}">
        	</div> 
        </dd>
      </dl>
 	
      <if condition='$Request.param.is_app_ad eq 1'>
     		<input name="pid" type="hidden" value="{$info.pid}">
      <else/>
	  <dl class="row">
        <dt class="tit" colspan="2">
          <label>广告位置：</label>
        </dt>
        <dd class="opt">
          <div>
          		<select name="pid" class="input-sm" class="form-control">
	                <volist name="position" id="item">
	                       <option value="{$item.position_id}" <if condition="$info[pid] eq $item[position_id]">selected</if>>{$item.position_name}</option>
	               </volist>                  
	            </select> 
          </div>          
        </dd>
      </dl>    
       </if>       
	  <dl class="row">
        <dt class="tit">
          <label>开始日期：</label>
        </dt>
        <dd class="opt">
            <input type="text" class="input-txt" id="start_time" name="begin"  value="{$info.start_time|default='2016-01-01'}"/>
          <span class="err"></span>
        </dd>
      </dl>    
	  <dl class="row">
        <dt class="tit">
          <label>结束时间：</label>
        </dt>
        <dd class="opt">
            <input type="text" class="input-txt" id="end_time" name="end"  value="{$info.end_time|default='2019-01-01'}"/>
          <span class="err"></span>
        </dd>
      </dl>        
      
      <dl class="row">
        <dt class="tit">
          <label>广告图片</label>
        </dt>
        <dd class="opt">
          <div class="input-file-show">
                        <span class="show">
                            <a id="img_a" target="_blank" class="nyroModal" rel="gal" href="{$info.ad_code}">
                              <i id="img_i" class="fa fa-picture-o" onmouseover="layer.tips('<img src={$info.ad_code}>',this,{tips: [1, '#fff']});" onmouseout="layer.closeAll();"></i>
                            </a>
                        </span>
           	            <span class="type-file-box">
                            <input type="text" id="ad_code" name="ad_code" value="{$info.ad_code}" class="type-file-text">
                            <input type="button" name="button" id="button1" value="选择上传..." class="type-file-button">
                            <input class="type-file-file" onClick="GetUploadify(1,'','ad','img_call_back')" size="30" hidefocus="true" nc_type="change_site_logo" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
                        </span>
          </div>
          <span class="err"></span>
          <p class="notic">请上传图片格式文件,建议图片尺寸400*168像素(宽*高, 如果不按要求上传图片将会导致前端广告显示不友好)</p>
        </dd>
      </dl>
      <if condition='$Request.param.is_app_ad eq 0'>
      <dl class="row">
        <dt class="tit">
          <label><em>*</em>背景颜色：</label>
        </dt>
        <dd class="opt">
          <input type="color" placeholder="背景颜色：" class="input-txt" name="bgcolor" value="{$info.bgcolor}"  />
		  <span class="err" id="err_bgcolor" style="color:#F00; display:none;"></span>
          <p class="notic"></p>
        </dd>
      </dl>   
      </if>           
      <if condition='$Request.param.is_app_ad eq 0'>   		 		       
      <dl class="row">
        <dt class="tit">
          <label>默认排序：</label>
        </dt>
        <dd class="opt">
          <input type="text" placeholder="排序" name="orderby" value="{$info.orderby}" class="input-txt">
          <span class="err"></span>
          <p class="notic"></p>
        </dd>
      </dl>
      </if>
      <div class="bot"><a href="JavaScript:void(0);" onclick="adsubmit()" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a></div>
    </div>
       <input type="hidden" name="act" value="{$act}">
       <input type="hidden" name="ad_id" value="{$info.ad_id}">
  </form>
</div>
 <script>
	 function adsubmit(){
		$('#handleposition').submit();
	}
	
	 function select_goods_dialog(){
		 var url = "/index.php?m=Admin&c=ad&a=search_goods";
         layer.open({
             type: 2,
             title: '选择商品',
             shadeClose: true,
             shade: 0.2,
             area: ['1020px', '75%'],
             content: url
         });
	 }
	 
	 
	function refresh_media_type(mediaType){
		if(mediaType > 2){ 
			 if(mediaType == 3){ 
				 //商品
				 $("#link_goods").show();
				 $("#link_goods").siblings().hide(); 
			 }else if(mediaType == 4){
				 //商品分类
				 $("#link_category").show(); 
				 $("#link_category").siblings().hide();
			 }else if(mediaType == 5){
				//商品分类
				 $("#link_url").show(); 
				 $("#link_url").siblings().hide();
			 } 
		 }else{
			//商品
			 $("#link_goods").show();
			 $("#link_goods").siblings().hide();
			 $("#media_type").find("option[value=3]").attr("selected",true);
		 } 
	}
 
    $(document).ready(function(){
		$('#start_time').layDate();
		$('#end_time').layDate();
		
		$("#media_type").on("change",function(){ 
			 var mediaType = $('#media_type option:selected').val();
			 console.log(mediaType);
			 refresh_media_type(mediaType);
		});
		
		<if condition="$Request.param.is_app_ad eq 1">  
			<if condition="$info.ad_id gt 0">
				var mtype = "{$info.media_type}";
				refresh_media_type(mtype);//如果是编辑
			<else/>
				refresh_media_type(3);//如果是编辑
		 	</if> 
		<else/>
		 	refresh_media_type(5);//如果是编辑
		</if>
		
		<if condition="$info['cat_id2'] gt 0">
			 // 商品分类第二个下拉菜单
			 get_category('{$info[cat_id1]}','cat_id2','{$info[cat_id2]}');
		</if>
		<if condition="$info['cat_id3'] gt 0">
			// 商品分类第二个下拉菜单
			 get_category('{$info[cat_id2]}','cat_id3','{$info[cat_id3]}');
		</if>
		 
	});
    
    function goods_call_back(goodsId,goodsName){
    	//选中的商品 
    	$('#goods_name').html(goodsName);
    	$('#goods_id').val(goodsId);
    	console.log("goodsId : "+goodsId);
    	layer.closeAll('iframe');
    }
    
     function img_call_back(fileurl_tmp)
     {
       $("#ad_code").val(fileurl_tmp);
       $("#img_a").attr('href', fileurl_tmp);
       $("#img_i").attr('onmouseover', "layer.tips('<img src="+fileurl_tmp+">',this,{tips: [1, '#fff']});");
     }
 </script>
</body>
</html>